// pages/myself/my-customer/myCustomer.js
const { validate } = require('../../../utils/validator.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    customerList: [],
    keyword: '',
    cdnPath: app.globalData.CDNPATH,
    height:0,
    scrollY:true,
    page: {
      currentPage: 1,
      pageSize: 10,
      total: 0,
    },
    rules: {
      keyword: [
        { validator(rule, value, callback) {
            const reg = /^[a-zA-Z\u4e00-\u9fa5]*$/
            if (!reg.test(value)) {
              callback(new Error('姓名需为2-10位中文或英文字符'))
            } else {
              callback()
            }
          } },
      ],
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getCustomerList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  input: function (e) {
    this.setData({
      keyword: e.detail.value,
      page: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      customerList: []
    })
    this.getCustomerList()

  },
  getCustomerList: function () {
    let { page, keyword, customerList } = this.data
    const params = {
      keyword
    }
    app.api.post({
      url: 'cpic_user_searchStudentUser',
      data: params
    }).then(res => {
      let arr = []
      customerList = []
      if (res.length > 0) {
        arr = res || []
        customerList.push(...arr)
        this.setData({
          customerList
        })
      }
      console.log(customerList)
    })
  },
  toDetail(e) {
    const info = JSON.stringify(e.currentTarget.dataset.info)
    wx.navigateTo({
      url: `../financial-manager-detail/financial-manager-detail?info=${info}`,
    })
  },
  toAddFinancialManager() {
    wx.navigateTo({
      url: '../add-financial-manager/addFinancialManager',
    })
  },
})

